<template>
	<div class="app">
		<div class="login">
			<h2>系统登录</h2>
			<el-form :model="dynamicValidateForm" ref="dynamicValidateForm" class="demo-dynamic">
				<el-form-item prop="email" :rules="[
					{ required: true, message: '请输入账户信息', trigger: 'blur' },
					{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
				]">
					<el-input v-model="dynamicValidateForm.email" class="email" ></el-input>
				</el-form-item>
				<img src="../../styles/denglu.png" alt="" class="img_denglu">
			</el-form>
			<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
				<el-form-item prop="pass">
					<el-input type="password" v-model="ruleForm.pass" autocomplete="off" class="passd"></el-input>
				</el-form-item>
				<img src="../../styles/pass.png" alt="" class="img_pass">
			</el-form>
			<el-button type="primary" class="login_button" @click="login">登录</el-button>
		</div>
		
	</div>
</template>

<script>
	export default {
		data() {
			var validatePass = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请输入密码'));
				} else {
					if (this.ruleForm.checkPass !== '') {
						this.$refs.ruleForm.validateField('checkPass');
					}
					callback();
				}
			};
			return {
				dynamicValidateForm: {
					domains: [{
						value: ''
					}],
					email: ''
				},
				ruleForm: {
					pass: '',
				},
				rules: {
					pass: [{
						validator: validatePass,
						trigger: 'blur'
					}],
				}
			};
		},
		methods:{
			getbg:function(){
				let bg = document.querySelector('.login .el-input__inner')
				bg.style.background = "#283442"
				bg.style.color = "#eee"
				bg.style.paddingLeft = "35px"
				let bg1 = document.querySelector('.passd .el-input__inner')
				bg1.style.background = "#283442"
				bg1.style.color = "#eee"
				bg1.style.paddingLeft = "35px"
			},
			login:function(){
				localStorage.setItem("userinfo",JSON.stringify({
					username:document.querySelector(".el-input__inner").value,
				}))
				this.$router.push({
					path:'/index',
				})
			}
		},
		mounted() {
			this.getbg()
		}
	}
</script>

<style lang="less" scoped>
	* {
		margin: 0;
		padding: 0;
	}

	.app {
		width: 100%;
		height: 97vh;
		background: #2C3A4A;
	}

	.login {
		text-align: center;
		width: 25%;
		margin: 0 auto;
		padding-top: 30vh;
		position: relative;
		h2 {
			color: #eee;
			margin-bottom: 30px;
		}
		.demo-dynamic{
			position: relative;
			.img_denglu{
				position: absolute;
				top: 10%;
				left: 0%;
			}
		}
		.demo-ruleForm{
			position: relative;
			.img_pass{
				position: absolute;
				top: 10%;
				left: 0%;
			}
		}
		.demo-ruleForm{
			margin-top: 20px;
		}
		.login_button{
			margin-top: 20px;
			width: 80%;
			height: 40px;
		}
	}
</style>
